/**
 * Created by zy on 2016/6/22.
 * 维修记录 - 六种修复公用方法
 */


;(function($, window, document, undefined){

    var save_path = $('#JQ_noninternal_save_path').val();

    // 防腐层修复 - 是否为补口
    var $select_isjoint = $('#JQ_select_isjoint').select3({search:false,title:'是否为补口'});
    if($select_isjoint.length > 0){
        // 填充补口
        DyyBase.ajax(defectApi.url_external_coat_isjoint(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_isjoint.add(json);
        });
    }
    // 防腐层修复 - 修复材料
    var $select_coat_material = $('#JQ_select_coat_material').select3({search:false,title:'修复材料'});
    if($select_coat_material.length > 0){
        // 填充修复材料
        DyyBase.ajax(defectApi.url_external_coat_material(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_coat_material.add(json);
        });
    }

    // 复合材料补强修复 - 修复方法
    var $select_composites_method = $('#JQ_select_composites_method').select3({search:false,title:'修复方法'});
    if($select_composites_method.length > 0){
        // 填充修复材料
        DyyBase.ajax(defectApi.url_external_composites_method(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_composites_method.add(json);
        });
    }
    // 复合材料补强修复 - 修复材料
    var $select_composites_material = $('#JQ_select_composities_material').select3({search:false,title:'修复材料'});
    if($select_composites_material.length > 0){
        // 填充修复材料
        DyyBase.ajax(defectApi.url_external_composites_material(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_composites_material.add(json);
        });
    }
    // 复合材料补强修复 - 修复层数
    var $select_composites_layer = $('#JQ_repairLayer');
    // 复合材料补强修复 - 固化时间
    var $select_composites_solid_time = $('#JQ_solidificationTime');
    // 复合材料补强修复 - 巴氏硬度
    var $select_composites_hardness = $('#JQ_hardness');
    // 复合材料补强修复 - 材料厂商
    var $select_composites_facturer = $('#JQ_materialManufacturer');

    // 钢质环氧套筒补强修复 - 套筒结构
    var $select_socket_structure = $('#JQ_socketStructure').select3({search:false,title:'套筒结构'});
    if($select_socket_structure.length > 0){
        // 套筒结构
        DyyBase.ajax(defectApi.url_external_sleeve_structure(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_socket_structure.add(json);
        });
    }
    // 钢质环氧套筒补强修复 - 材质A - B
    var $select_material_a = $('#JQ_material_a').select3({search:false,title:'材质类型'});
    var $select_material_b = $('#JQ_material_b').select3({search:false,title:'材质'});
    if($select_material_a.length > 0){
        // 材质A
        DyyBase.ajax(defectApi.url_external_sleeve_material_a(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_material_a.add(json);
        });

        // 材质B
        $select_material_a.element.on('select',function(e,v){
            var parentId = v || $select_material_a.val();
            if(parentId){
                DyyBase.ajax(defectApi.url_external_sleeve_material_b(),{parentId:parentId},function(dataset){
                    var json = DyyBase.getSelect(dataset);
                    $select_material_b.add(json);
                });
            }else{
                $select_material_b.add([]);
            }
        });
    }
    // 钢质环氧套筒补强修复 - 壁厚
    var $select_wall_thickness = $('#JQ_wallThickness');
    // 钢质环氧套筒补强修复 - 外径
    var $select_od = $('#JQ_od');
    // 钢质环氧套筒补强修复 - 灌注工艺
    var $select_perfusion_process = $('#JQ_perfusionProcess');
    // 钢质环氧套筒补强修复 - 生产厂商
    var $select_manufacturer = $('#JQ_manufacturer');

    // AB型套筒补强修复 - 焊材牌号
    var $select_welding_grade = $('#JQ_weldingGrade');
    // AB型套筒补强修复 - 焊接方法
    var $select_welding_method = $('#JQ_weldingMethod');
    // AB型套筒补强修复 - 套筒长度
    var $select_length = $('#JQ_length');

    // 换管 - 制管方式
    var $select_manu_pipe_type = $('#JQ_manuPipeType').select3({search:false,title:'制管方式'});
    if($select_manu_pipe_type.length > 0){
        // 制管方式
        DyyBase.ajax(defectApi.url_external_replace_manupipe(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_manu_pipe_type.add(json);
        });
    }
    // 换管 - 管径
    var $select_diameter = $('#JQ_diameter').select3({search:false,title:'管径'});
    if($select_diameter.length > 0){
        // 管径
        DyyBase.ajax(defectApi.url_external_replace_diameter(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_diameter.add(json);
        });
    }
    // 换管 - 防腐层材料
    var $select_coat_materialc = $('#JQ_coatingMaterial').select3({search:false,title:'防腐层材料'});
    if($select_coat_materialc.length > 0){
        // 防腐层材料
        DyyBase.ajax(defectApi.url_external_replace_coat_material(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_coat_materialc.add(json);
        });
    }
    // 换管 - 防腐等级
    var $select_coat_grade = $('#JQ_coatingGrade').select3({search:false,title:'防腐等级'});
    if($select_coat_grade.length > 0){
        // 防腐等级
        DyyBase.ajax(defectApi.url_external_replace_coat_grade(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_coat_grade.add(json);
        });
    }
    // 换管 - 起点坐标(x)
    var $select_start_x = $('#JQ_startX');
    // 换管 - 起点坐标(y)
    var $select_start_y = $('#JQ_startY');
    // 换管 - 起点坐标(z)
    var $select_start_z = $('#JQ_startZ');
    // 换管 - 终点坐标(x)
    var $select_end_x = $('#JQ_endX');
    // 换管 - 终点坐标(y)
    var $select_end_y = $('#JQ_endY');
    // 换管 - 终点坐标(z)
    var $select_end_z = $('#JQ_endZ');
    // 换管 - 起始里程(m)
    var $select_start_mileage = $('#JQ_startMileage');
    // 换管 - 终点里程(m)
    var $select_end_mileage = $('#JQ_endMileage');
    // 换管 - 换管长度(m)
    var $select_lenth = $('#JQ_lenth');

    // 换管 - 焊接 - WPS编号
    var $select_wps_number = $('#JQ_wpsNumber');
    // 换管 - 焊接 - 无损检测类型
    var $select_ndt_type = $('#JQ_ndtType').select3({search:false,title:'无损检测类型'});
    if($select_ndt_type.length > 0){
        // 无损检测类型
        DyyBase.ajax(defectApi.url_external_ndttype(),{},function(dataset){
            var json = DyyBase.getSelect(dataset);
            $select_ndt_type.add(json);
        });
    }
    // 换管 - 焊接 - 是否返修
    var $select_repairind = $('#JQ_repairind').select3({
        data: [
            {id:1,text:'是'},
            {id:0,text:'否'}
        ],
        search:false,
        title:'无损检测类型'
    });
    // 换管 - 焊接 - 焊接材料
    var $select_weld_material = $('#JQ_weldingMaterial');
    // 换管 - 焊接 - 检测日期
    var $select_test_date = $('#JQ_testDate_input');
    // 换管 - 焊接 - 检测单位
    var $select_testingCompany = $('#JQ_testingCompany');
    // 焊接 - 备注
    var $select_weldingRemark = $('#JQ_createRemark_weldingRemark_01');


    // 通用 - 环境温度
    var $select_environmentalTemperature = $('#JQ_environmentalTemperature');
    // 通用 - 管表温度
    var $select_surfaceTemperature = $('#JQ_surfaceTemperature');
    // 通用 - 修复长度
    var $select_repairLength = $('#JQ_repairLength');
    // 通用 - 厚度
    var $select_repairThickness = $('#JQ_repairThickness');
    // 通用 - 电火花检漏电压
    var $select_edmLeak = $('#JQ_edmLeak');
    // 通用 - 工作量
    var $select_workload = $('#JQ_workload');
    // 通用 - 材料厂商
    var $select_materialManufacturer = $('#JQ_materialManufacturer');
    // 通用 - 备注
    var $select_createRemark = $('#JQ_createRemark');


    // 获取数据 - 1
    var getData = function(tag){
        // 返回此对象
        var data = {};

        // 复合材料补强修复
        if(tag == 'composites'){
            /* 复合材料补强修复 - start */
            // 缺陷ID
            data.mode = true;
            data.defectId = function(){
                var v = $('#JQ_defectId').val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 修复方法
            data.repairMethod = function(){
                var v = $select_composites_method.val();
                if(v){
                    return v;
                }else{
                    $select_composites_method.TIP({content:'修复方法不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 修复材料
            data.repairMaterial = function(){
                var v = $select_composites_material.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 修复长度
            data.repairLength = function(){
                var v = $select_repairLength.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_repairLength.TIP({
                            content: '修复长度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_repairLength.TIP({
                        content: '修复长度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 修复层数
            data.repairLayer = function(){
                var v = $select_composites_layer.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_composites_layer.TIP({
                            content: '修复层数须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }
                return '';
            }();
            // 环境温度
            data.environmentalTemperature = function(){
                var v = $select_environmentalTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_environmentalTemperature.TIP({
                            content: '环境温度须为数字!'
                        });
                        data.mode = false;
                    }
                }else{
                    return '';
                }
            }();
            // 管表温度
            data.surfaceTemperature = function(){
                var v = $select_surfaceTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_surfaceTemperature.TIP({
                            content: '管表温度须为数字!'
                        });
                        data.mode = false;
                    }
                }else{
                    return '';
                }
            }();
            // 固化时间
            data.solidificationTime = function(){
                var v = $select_composites_solid_time.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_composites_solid_time.TIP({
                            content: '固化时间须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }
                return '';
            }();
            // 巴氏硬度
            data.hardness = function(){
                var v = $select_composites_hardness.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_composites_hardness.TIP({
                            content: '巴氏硬度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }
                return '';
            }();
            // 材料厂商
            data.materialManufacturer = function(){
                var v = $select_composites_facturer.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 备注
            data.createRemark = function(){
                var v = $select_createRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 照片
            data.att = function(){
                var $spans = $('span.zy-noninternal-span-img');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
            /* 复合材料补强修复 - start */
        }

        // 防腐层修复
        if(tag == 'coat'){
            /* 防腐层修复 - start */
            // 缺陷ID
            data.mode = true;
            data.defectId = function(){
                var v = $('#JQ_defectId').val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 是否为补口
            data.isJoint = function(){
                var v = $select_isjoint.val();
                if(v){
                    return v;
                }else{
                    $select_isjoint.TIP({content:'是否为补口不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 环境温度
            data.environmentalTemperature = function(){
                var v = $select_environmentalTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_environmentalTemperature.TIP({
                            content: '环境温度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_environmentalTemperature.TIP({
                        content: '环境温度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 管表温度
            data.surfaceTemperature = function(){
                var v = $select_surfaceTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_surfaceTemperature.TIP({
                            content: '管表温度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_surfaceTemperature.TIP({
                        content: '管表温度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 修复材料
            data.repairMaterial = function(){
                var v = $select_coat_material.val();
                if(v){
                    return v;
                }else{
                    $select_coat_material.TIP({
                        content: '修复材料不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 修复长度
            data.repairLength = function(){
                var v = $select_repairLength.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_repairLength.TIP({
                            content: '修复长度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_repairLength.TIP({
                        content: '修复长度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 厚度
            data.repairThickness = function(){
                var v = $select_repairThickness.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_repairThickness.TIP({
                            content: '厚度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_repairThickness.TIP({
                        content: '不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 电火花检漏电压
            data.edmLeak = function(){
                var v = $select_edmLeak.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_edmLeak.TIP({
                            content: '电火花检漏电压须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_edmLeak.TIP({
                        content: '电火花检漏不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 工作量
            data.workload = function(){
                var v = $select_workload.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 材料厂商
            data.materialManufacturer = function(){
                var v = $select_materialManufacturer.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 备注
            data.createRemark = function(){
                var v = $select_createRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 照片
            data.att = function(){
                var $spans = $('span.zy-noninternal-span-img');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
            /* 防腐层修复 - end */
        }

        // 钢质环氧套筒补强修复
        if(tag == 'epoxy_sleeve'){
            /* 钢质环氧套筒补强修复 - start */
            // 缺陷ID
            data.mode = true;
            data.defectId = function(){
                var v = $('#JQ_defectId').val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 套筒结构
            data.socketStructure = function(){
                var v = $select_socket_structure.val();
                if(v){
                    return v;
                }else{
                    $select_socket_structure.TIP({content:'套筒结构不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 壁厚
            data.wallThickness = function(){
                var v = $select_wall_thickness.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_wall_thickness.TIP({content:'壁厚须为数字!'});
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_wall_thickness.TIP({content:'壁厚不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 外径
            data.od = function(){
                var v = $select_od.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_od.TIP({content:'外径须为数字!'});
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_od.TIP({content:'外径不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 材质
            data.material = function(){
                var v = $select_material_b.val();
                if(v){
                    return v;
                }else{
                    $select_material_b.TIP({content:'材质不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 修复长度
            data.repairLength = function(){
                var v = $select_repairLength.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_repairLength.TIP({
                            content: '修复长度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_repairLength.TIP({
                        content: '修复长度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 环境温度
            data.environmentalTemperature = function(){
                var v = $select_environmentalTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_environmentalTemperature.TIP({
                            content: '环境温度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_environmentalTemperature.TIP({
                        content: '环境温度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 管表温度
            data.surfaceTemperature = function(){
                var v = $select_surfaceTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_surfaceTemperature.TIP({
                            content: '管表温度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_surfaceTemperature.TIP({
                        content: '管表温度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 灌注工艺
            data.perfusionProcess = function(){
                var v = $select_perfusion_process.val();
                if(v){
                    return v;
                }else{
                    $select_perfusion_process.TIP({
                        content: '灌注工艺不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 工作量
            data.workload = function(){
                var v = $select_workload.val();
                if(v){
                    return v;
                }else{
                    $select_workload.TIP({
                        content: '工作量不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 生产厂商
            data.manufacturer = function(){
                var v = $select_manufacturer.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 备注
            data.createRemark = function(){
                var v = $select_createRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 照片
            data.att = function(){
                var $spans = $('span.zy-noninternal-span-img');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
            /* 钢质环氧套筒补强修复 - end */
        }

        // AB型套筒补强修复
        if(tag == 'abtype'){
            /* A型套筒补强修复 - start */
            // 缺陷ID
            data.mode = true;
            data.defectId = function(){
                var v = $('#JQ_defectId').val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 套筒信息(壁厚)
            data.wallThickness = function(){
                var v = $select_wall_thickness.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_wall_thickness.TIP({content:'壁厚须为数字!'});
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_wall_thickness.TIP({content:'壁厚不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 套筒长度
            data.length = function(){
                var v = $select_length.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_length.TIP({content:'套筒长度须为数字!'});
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_length.TIP({content:'套筒长度不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 材质B
            data.material = function(){
                var v = $select_material_b.val();
                if(v){
                    return v;
                }else{
                    $select_material_b.TIP({content:'材质不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 环境温度
            data.environmentalTemperature = function(){
                var v = $select_environmentalTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_environmentalTemperature.TIP({
                            content: '环境温度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_environmentalTemperature.TIP({
                        content: '环境温度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 管表温度
            data.surfaceTemperature = function(){
                var v = $select_surfaceTemperature.val();
                if(v){
                    if(!(isNaN(v))){
                        return v;
                    }else{
                        $select_surfaceTemperature.TIP({
                            content: '管表温度须为数字!'
                        });
                        data.mode = false;
                    }
                    return v;
                }else{
                    $select_surfaceTemperature.TIP({
                        content: '管表温度不能为空!'
                    });
                    data.mode = false;
                }
                return '';
            }();
            // 焊材牌号
            data.weldingGrade = function(){
                var v = $select_welding_grade.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 焊接方法
            data.weldingMethod = function(){
                var v = $select_welding_method.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 备注
            data.createRemark = function(){
                var v = $select_createRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 照片
            data.att = function(){
                var $spans = $('span.zy-noninternal-span-img');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
            /* A型套筒补强修复 - end */
        }

        // 换管 - 焊接
        if(tag == 'pipeWeld'){
            // 缺陷ID
            data.mode = true;
            data.defectId = function(){
                var v = $('#JQ_defectId').val();
                if(v){
                    return v;
                }
                return '';
            }();
            /* 换管 - start */
            // 起点坐标(x)
            data.startX = function(){
                return $select_start_x.val();
            }();
            // 起点坐标(y)
            data.startY = function(){
                return $select_start_y.val();
            }();
            // 起点坐标(z)
            data.startZ = function(){
                return $select_start_z.val();
            }();
            // 终点坐标(x)
            data.endX = function(){
                return $select_end_x.val();
            }();
            // 终点坐标(y)
            data.endY = function(){
                return $select_end_y.val();
            }();
            // 终点坐标(z)
            data.endZ = function(){
                return $select_end_z.val();
            }();
            // 起始里程(m)
            data.startMileage = function(){
                return $select_start_mileage.val();
            }();
            // 终点里程(m)
            data.endMileage = function(){
                return $select_end_mileage.val();
            }();
            // 换管长度(m)
            data.lenth = function(){
                return $select_lenth.val();
            }();
            // 材质B
            data.material = function(){
                return $select_material_b.val();
            }();
            // 制管方式
            data.manuPipeType = function(){
                return $select_manu_pipe_type.val();
            }();
            // 管径
            data.diameter = function(){
                return $select_diameter.val();
            }();
            // 壁厚
            data.wallThickness = function(){
                return $select_wall_thickness.val();
            }();
            // 防腐层材料
            data.coatingMaterial = function(){
                return $select_coat_materialc.val();
            }();
            // 防腐等级
            data.coatingGrade = function(){
                return $select_coat_grade.val();
            }();
            // 换管图片
            data.imgsReplace = function(){
                var $spans = $('span.imgsReplace');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
            // 备注
            data.createRemark = function(){
                var v = $select_createRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            /* 换管 - end */

            /* 换管 - 焊接 - start */
            // 环焊缝编号数组
            data.gwwNumbers = function(){
                var arr = [];
                var $nums = $('input.gww-number');
                $nums.each(function(){
                    var $this = $(this);
                    if(!($this.hasClass('non'))){
                        var v = $this.val();
                        if(v){
                            arr.push(v);
                        }else{
                            $this.TIP({content:'环焊缝编号不能为空!'});
                            data.mode = false;
                        }
                    }
                });
                return arr;
            }();
            // x坐标数组
            data.x = function(){
                var arr = [];
                var $nums = $('input.gww-x');
                $nums.each(function(){
                    var $this = $(this);
                    if(!($this.hasClass('non'))){
                        var v = $this.val();
                        if(v){
                            arr.push(v);
                        }else{
                            $this.TIP({content:'采集坐标(X)不能为空!'});
                            data.mode = false;
                        }
                    }
                });
                return arr;
            }();
            // y坐标数组
            data.y = function(){
                var arr = [];
                var $nums = $('input.gww-y');
                $nums.each(function(){
                    var $this = $(this);
                    if(!($this.hasClass('non'))){
                        var v = $this.val();
                        if(v){
                            arr.push(v);
                        }else{
                            $this.TIP({content:'采集坐标(Y)不能为空!'});
                            data.mode = false;
                        }
                    }
                });
                return arr;
            }();
            // z坐标数组
            data.z = function(){
                var arr = [];
                var $nums = $('input.gww-z');
                $nums.each(function(){
                    var $this = $(this);
                    if(!($this.hasClass('non'))){
                        var v = $this.val();
                        if(v){
                            arr.push(v);
                        }else{
                            $this.TIP({content:'采集坐标(Z)不能为空!'});
                            data.mode = false;
                        }
                    }
                });
                return arr;
            }();
            // WPS编号
            data.wpsNumber = function(){
                var v = $select_wps_number.val();
                if(v){
                    return v;
                }else{
                    $select_wps_number.TIP({content:'WPS编号不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 无损检测类型
            data.ndtType = function(){
                var v = $select_ndt_type.val();
                if(v){
                    return v;
                }else{
                    $select_ndt_type.TIP({content:'无损检测类型不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 是否返修
            data.repairind = function(){
                var v = $select_repairind.val();
                if(v){
                    return v;
                }else{
                    $select_repairind.TIP({content:'是否返修不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 焊接材料
            data.weldingMaterial = function(){
                var v = $select_weld_material.val();
                if(v){
                    return v;
                }else{
                    $select_weld_material.TIP({content:'焊接材料不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 检测日期
            data.testDate = function(){
                var v = $select_test_date.val();
                if(v){
                    return v;
                }else{
                    $select_test_date.TIP({content:'检测日期不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 检测单位
            data.testingCompany = function(){
                var v = $select_testingCompany.val();
                if(v){
                    return v;
                }else{
                    $select_testingCompany.TIP({content:'检测单位不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            // 焊接图片
            data.imgsWelding = function(){
                var $spans = $('span.imgsWelding');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
            // 备注
            data.weldingRemark = function(){
                var v = $select_weldingRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            /* 换管 - 焊接 - end */
        }

        // 其他
        if(tag == 'other'){
            // 缺陷ID
            data.mode = true;
            data.defectId = function(){
                var v = $('#JQ_defectId').val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 备注
            data.createRemark = function(){
                var v = $select_createRemark.val();
                if(v){
                    return v;
                }
                return '';
            }();
            // 照片
            data.att = function(){
                var $spans = $('span.zy-noninternal-span-img');
                var arr = [];
                if($spans.length > 0){
                    $spans.each(function(){
                        var $this_label = $(this);
                        arr.push($this_label.attr('data-id'));
                    });
                }
                return arr;
            }();
        }

        // 组装返回数据
        return DyyBase.convertToArr(data);
    };

    // 获取数据 - 换管
    var getData2 = function(){
        // 返回此对象
        var data = {};
        // 换管
        // 缺陷ID
        data.mode = true;
        /* 换管 - start */
        // 起点坐标(x)
        data.startX = function(){
            var v = $select_start_x.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_start_x.TIP({content:'起点坐标(x)须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_start_x.TIP({content:'起点坐标(x)不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 起点坐标(y)
        data.startY = function(){
            var v = $select_start_y.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_start_y.TIP({content:'起点坐标(y)须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_start_y.TIP({content:'起点坐标(y)不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 起点坐标(z)
        data.startZ = function(){
            var v = $select_start_z.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_start_z.TIP({content:'起点坐标(z)须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_start_z.TIP({content:'起点坐标(z)不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 终点坐标(x)
        data.endX = function(){
            var v = $select_end_x.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_end_x.TIP({content:'终点坐标(x)须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_end_x.TIP({content:'终点坐标(x)不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 终点坐标(y)
        data.endY = function(){
            var v = $select_end_y.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_end_y.TIP({content:'终点坐标(y)须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_end_y.TIP({content:'终点坐标(y)不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 终点坐标(z)
        data.endZ = function(){
            var v = $select_end_z.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_end_z.TIP({content:'终点坐标(z)须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_end_z.TIP({content:'终点坐标(z)不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 起始里程(m)
        data.startMileage = function(){
            var v = $select_start_mileage.val();
            if(v){
                return v;
            }
            return '';
        }();
        // 终点里程(m)
        data.endMileage = function(){
            var v = $select_end_mileage.val();
            if(v){
                return v;
            }
            return '';
        }();
        // 换管长度(m)
        data.lenth = function(){
            var v = $select_lenth.val();
            if(v){
                return v;
            }
            return '';
        }();
        // 材质B
        data.material = function(){
            var v = $select_material_b.val();
            if(v){
                return v;
            }else{
                $select_material_b.TIP({content:'材质不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 制管方式
        data.manuPipeType = function(){
            var v = $select_manu_pipe_type.val();
            if(v){
                return v;
            }else{
                $select_manu_pipe_type.TIP({content:'制管方式不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 管径
        data.diameter = function(){
            var v = $select_diameter.val();
            if(v){
                return v;
            }else{
                $select_diameter.TIP({content:'管径不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 壁厚
        data.wallThickness = function(){
            var v = $select_wall_thickness.val();
            if(v){
                if(!(isNaN(v))){
                    return v;
                }else{
                    $select_wall_thickness.TIP({content:'壁厚须为数字!'});
                    data.mode = false;
                }
                return v;
            }else{
                $select_wall_thickness.TIP({content:'壁厚不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 防腐层材料
        data.coatingMaterial = function(){
            var v = $select_coat_materialc.val();
            if(v){
                return v;
            }else{
                $select_coat_materialc.TIP({content:'防腐层材料不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        // 防腐等级
        data.coatingGrade = function(){
            var v = $select_coat_grade.val();
            if(v){
                return v;
            }else{
                $select_coat_grade.TIP({content:'防腐等级不能为空!'});
                data.mode = false;
            }
            return '';
        }();
        /* 换管 - end */

        // 返回校验对象
        return data;
    };

    // 公用方法 - 提交
    $('#JQ_noninternal_submit_btn').click(function(){
        // 验证
        var $form = $('#JQ_create_form');
        var bool = $form.verify();
        if(bool){
            var type = $('#JQ_noninternal_save_path').val();
            var param = getData(type);
            if(param[0].value){
                // 路径
                var save_url = '';
                switch (save_path){
                    case 'epoxy_sleeve':
                        save_url = defectApi.url_external_sleeve_save();
                        break;
                    case 'coat':
                        save_url = defectApi.url_external_coat_save();
                        break;
                    case 'composites':
                        save_url = defectApi.url_external_composites_save();
                        break;
                    case 'abtype':
                        save_url = defectApi.url_external_abtype_save();
                        break;
                    case 'other':
                        save_url = defectApi.url_external_other_save();
                        break;
                    case 'pipeWeld':
                        save_url = defectApi.url_external_replace_save();
                        break;
                    default:
                        break;
                }
                // 保存
                DyyBase.ajax(save_url,param,function(dataset){
                    if(dataset.bool){
                        $(this).MSG({
                            type: 'success',
                            content: '添加成功!',
                            yesBtnAct: DyyBase.goToPage,
                            closeBtnAct: DyyBase.goToPage,
                            goToUrl: DyyBase.root_path+'/pbf/external/externalInspection.html'
                        });
                    }else{
                        $(this).MSG({
                            type: 'error',
                            content: '添加失败!'
                        });
                    }
                });
            }
        }
    });

    // 上传图片
    var upcount = 0;    // 已上传图片数
    $('button.zy-noninternal-upload-button').each(function(){

        var $this_button = $(this);
        var param = $this_button.attr('data-type');
        var dom_btn = $this_button.get(0);

        // 实例化一个plupload上传对象
        var uploader = new plupload.Uploader({
            browse_button: dom_btn,
            url: DyyBase.url_upload_file(),
            filters: {
                mime_types: [
                    {title:'Image files', extensions: 'jpg,gif,png'}
                ]
            },
            multipart_params: {
                type: param
            },
            flash_swf_url: DyyBase.root_path+'/static/js/plugin/plupload/Moxie.swf',
            silverlight_xap_url: DyyBase.root_path+'/static/js/plugin/plupload/Moxie.xap',
            init: {
                BeforeUpload: function(u,f){},
                UploadProgress: function(u,f){},
                FileUploaded: function(u,f,info){
                    showUploadImg(info,$this_button);
                },
                UploadComplete: function(u,f){},
                Error: function(u,f){
                    if(f.code == -601){
                        var msg = f.file.name + '&nbsp;&nbsp;文件格式不正确!<p>请上传 (jpg,jpeg,gif,png) 格式图片!</p>';
                        $this_button.MSG({
                            type: 'error',
                            content: msg,
                            contentTitle: f.file.name,
                            contentAddon: '&nbsp;&nbsp;文件格式不正确!',
                            contentMust: '<p>请上传 (jpg,jpeg,gif,png) 格式图片</p>'
                        });
                    }
                },
                FilesAdded: function(u,f){
                    // 移除列队中的文件
                    function RF(u,f){
                        for(var j = 0, len = f.length; j < len; j++){
                            u.removeFile(f[j]);
                        }
                    }
                    if(f.length > 8){
                        RF(u,f);
                        $this_button.MSG({
                            type: 'error',
                            content: '上传图片数量不超过8张！'
                        });
                    }else{
                        //upcount = upcount + f.length;
                        upcount = parseInt($this_button.attr('data-count')) + f.length;
                        if(upcount > 8){
                            RF(u,f); upcount = upcount - f.length;
                            $this_button.MSG({
                                type: 'error',
                                content: '上传图片数量不超过8张！<br>您已上传 '+upcount+' 张'
                            });
                        }else{
                            $this_button.attr('data-count', upcount);
                            uploader.start();
                        }
                    }
                }
            }
        });

        // 初始化
        uploader.init();
    });

    // 为删除照片按钮添加代理事件
    $('label.zy-noninternal-upload-label').delegate('i','click',function(event){
        var $this_i = $(this);
        var attId = $this_i.attr('data-id');
        DyyBase.ajax(defectApi.url_external_delete_img(),{attId:attId},function(dataset){
            if(dataset.bool){
                upcount = upcount - 1;
                var $btn = $this_i.parent('span').parent('label').siblings('button.zy-noninternal-upload-button');
                $btn.attr('data-count',upcount);
                $this_i.parent('span.zy-noninternal-span-img').remove();
            }
        });
        event.stopPropagation();
    });

    // 添加展示上传完成后的图片
    function showUploadImg(o,btn){
        var json = $.parseJSON(o.response);
        var path = DyyBase.file_path+json.result.path;
        var tag = btn.attr('data-tag') ? btn.attr('data-tag') : '';
        var $span = $('<span class="zy-noninternal-span-img '+tag+'" data-path="'+path+'" data-id="'+json.result.id+'"><i data-id="'+json.result.id+'" title="删除照片">×</i><img src="'+path+'"></span>');
        var $label = btn.siblings('label.zy-noninternal-upload-label');
        $label.append($span);
    }

    // 返回列表
    $('#JQ_noninternal_change_piep_goback_btn').click(function(){
        window.location.href = DyyBase.root_path + '/pbf/external/externalInspection.html';
    });

    // 换管 - 下一步啊
    $('#JQ_noninternal_change_pipe_gonext_btn').click(function(){
        // 验证第一步
        var $form_01 = $('#JQ_step01_form');
        var bool = $form_01.verify();
        if(bool){
            var param = getData2();
            if(param.mode){
                $('#JQ_step_01').hide();
                $('#JQ_step_02').show();
                $(window).scrollTop(0);
            }
        }
    });

    // 换管 - 焊接 - 返回
    $('#JQ_noninternal_pipe_weld_back').click(function(){
        window.location.href = DyyBase.root_path + '/pbf/external/externalInspection.html';
    });

    // 添加环焊缝
    $('#JQ_add_pipe_weld').click(function(){
        $('div.zy-pipe-weld-third').show();
        $('div.zy-pipe-weld-third').find('input').removeClass('non');
    });

    // 删除第3条环焊缝
    $('#JQ_pipe_weld_third_delete').click(function(){
        var $this_btn = $(this);
        var $parent_div = $this_btn.parent().parent().parent();
        $parent_div.find('input.zy-i-input').addClass('non').val('');
        $parent_div.hide();
    });

    // 计算起始里程(m)

    // 终点里程(m)

    // 换管长度(m)

    // 返回列表
    $('#JQ_noninternal_repair_goback').click(function(){
        DyyBase.goToPage(DyyBase.root_path+'/pbf/external/externalInspection.html');
    });

})(jQuery,window,document);